package de.tuberlin.dima.minidb.parser;


import de.tuberlin.dima.minidb.api.ExtensionFactory;


/**
 * Simple factory for an SQLParser that returns an instance of the parser through
 * accessing the API extension point.
 * 
 * @author Stephan Ewen (sewen@cs.tu-berlin.de)
 */
public abstract class ParserFactory
{
	/**
	 * The extension point that is used to actually instantiate the parser. 
	 */
	private static ExtensionFactory registry;

	
	/**
	 * Returns a SQLParser for the given SQL string. The parser is instantiated by
	 * accessing the API extension point.
	 * 
	 * @param sqlStatement The statement to be parsed.
	 * @return A parser to parse the given statement.
	 */
	public static SQLParser createParser(String sqlStatement)
	{
		if (registry == null) {
			registry = ExtensionFactory.getExtensionFactory();
		}
		
		return registry.getParser(sqlStatement);
	}
}
